package com.yekaile.carsystem.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yekaile.carsystem.controller.vo.OrderFormVO;
import com.yekaile.carsystem.entity.OrderForm;
import com.yekaile.carsystem.service.OrderFormService;
import com.yekaile.carsystem.util.Result;
import lombok.AllArgsConstructor;
import org.apache.http.HttpStatus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yekaile
 */
@RestController
@RequestMapping("orderform")
@AllArgsConstructor(onConstructor_=@Autowired)
public class OrderFormController {

    OrderFormService orderFormService;




    @GetMapping("getOrderForm")
    @RequiresPermissions("orderform:select")
    public Result<PageInfo<OrderForm>> getOrderForm(OrderForm orderForm, @RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                                    @RequestParam(defaultValue = "8", required = false) Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<OrderForm> orderForms = orderFormService.listOrderForm(orderForm);
        PageInfo<OrderForm> pageInfo = new PageInfo<>(orderForms);
        return new Result<>(HttpStatus.SC_OK, "success", pageInfo);
    }

    @GetMapping("getOrderFormDetail/{id}")
    @RequiresPermissions("orderform:select")
    public Result<OrderFormVO> getOrderFormDetail(@PathVariable("id") Integer orderFormId) {
        OrderFormVO orderFormVO = orderFormService.getOrderFormVO(orderFormId);
        return new Result<>(HttpStatus.SC_OK, "success", orderFormVO);
    }

    @DeleteMapping("deleteOrderForm/{id}")
    @RequiresPermissions("orderform:delete")
    public Result<String>deleteOrderForm(@PathVariable("id")Integer orderFormId){
        orderFormService.deleteOrderForm(orderFormId);
        return new Result<>(HttpStatus.SC_NO_CONTENT, "success");
    }

}
